<?php $this->load->view("partial/header"); ?>
<div id="page_title" style="margin-bottom:8px;"><?php echo lang('reports_report_input'); ?></div>
<style type='text/css'>
    #search_form input {
        background: none repeat scroll 0 0 transparent;
        border: medium none;
        font-size: 18px;
        margin-top: 9px;
        padding: 6px 10px;
        vertical-align: top;
        width: 205px;
    }
    #search_form{
        height:50px;
    }
    #spinner {
        margin-left: -16px;
        margin-top: 16px;
    }
    .ui-autocomplete-loading { background: white url('<?php echo base_url(); ?>/images/ui-anim_basic_16x16.gif') right center no-repeat; }
    .ui-menu .ui-menu-item a {font-size:14px;}
</style>
<?php
if(isset($error))
{
	echo "<div class='error_message'>".$error."</div>";
}
?>
	<?php echo form_label(lang('reports_date_range'), 'report_date_range_label', array('class'=>'required')); ?>
	<div id='report_date_range_simple'>
		<input type="radio" name="report_type" id="simple_radio" value='simple' checked='checked'/>
		<?php echo form_dropdown('report_date_range_simple',$report_date_range_simple, '', 'id="report_date_range_simple"'); ?>
	</div>
	
	<div id='report_date_range_complex'>
		<input type="radio" name="report_type" id="complex_radio" value='complex' />
		<?php echo form_dropdown('start_month',$months, $selected_month, 'id="start_month"'); ?>
		<?php echo form_dropdown('start_day',$days, $selected_day, 'id="start_day"'); ?>
		<?php echo form_dropdown('start_year',$years, $selected_year, 'id="start_year"'); ?>
		-
		<?php echo form_dropdown('end_month',$months, $selected_month, 'id="end_month"'); ?>
		<?php echo form_dropdown('end_day',$days, $selected_day, 'id="end_day"'); ?>
		<?php echo form_dropdown('end_year',$years, $selected_year, 'id="end_year"'); ?>
	</div>
	<!-- filter -->
    <div id="custom_filter">
        <div class="ui-widget">
            <form action="<?php echo base_url(); ?>/report/filter_items" medthod='post'>
            <ul class="form">
                <li>
                    <label for="cat"><b>Category:</b></label>
                    <select id='cat' style='margin-right:5px;'>
                        <option value='1'>All</option>
                        <option value="0">Name</option>
                    </select>
                    <input id="category" size="21" value='0' style='display:none' name='category'  />
                </li>
                <li>
                    <label for="stock"><b>Stock:</b></label>
                    <select name='stock' id="stock">
                        <option value='1'>All</option>
                        <option value="order">Order</option>
                    </select>
                </li>
                <li>
                    <label for="items"><b>Items:</b></label>
                    <input id="items" size="30" value='0' name='name' />
                </li>
                <li>
                    <label for="barcodes"><b>Barcode:</b></label>
                    <input id="barcodes" size="30" value='0' name='barcode' />
                </li>
                <li>
                    <label for="serial_number"><b>S/N:</b></label>
                    <input id="serial_number" size="30" value='0' name='serial_number' />
                </li>
            </ul>
            </form>
        </div>         
    </div>
    <!-- end filter -->
	<?php echo form_label(lang('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required')); ?>
	<div id='report_sale_type'>
		<?php echo form_dropdown('sale_type',array('all' => lang('reports_all'), 'sales' => lang('reports_sales'), 'returns' => lang('reports_returns')), 'all', 'id="sale_type"'); ?>
	</div>
	
	<div>
		<?php echo lang('reports_export_to_excel'); ?>: <input type="radio" name="export_excel" id="export_excel_yes" value='1' /> <?php echo lang('common_yes'); ?>
		<input type="radio" name="export_excel" id="export_excel_no" value='0' checked='checked' /> <?php echo lang('common_no'); ?>
	</div>

<?php
echo form_button(array(
	'name'=>'generate_report',
	'id'=>'generate_report',
	'content'=>lang('common_submit'),
	'class'=>'submit_button')
);
?>

<?php $this->load->view("partial/footer"); ?>

<script type="text/javascript" language="javascript">
$(document).ready(function()
{
	$("#generate_report").click(function()
	{
		var sale_type = $("#sale_type").val();
		var export_excel = 0;
		if ($("#export_excel_yes").attr('checked'))
		{
			export_excel = 1;
		}
		
		if ($("#simple_radio").attr('checked'))
		{
			window.location = window.location+'/'+$("#report_date_range_simple option:selected").val() + '/'+sale_type+ '/'+$('#category').val()+'/'+$('#stock').val()+'/'+ $('#items').val()+'/'+ $('#barcodes').val()+'/'+ $('#serial_number').val()+'/'+export_excel;
		}
		else
		{
			var start_date = $("#start_year").val()+'-'+$("#start_month").val()+'-'+$('#start_day').val();
			var end_date = $("#end_year").val()+'-'+$("#end_month").val()+'-'+$('#end_day').val();
	
			window.location = window.location+'/'+start_date + '/'+ end_date + '/'+sale_type+'/'+ $('#category').val()+'/'+$('#stock').val()+'/'+ $('#items').val()+'/'+ $('#barcodes').val()+'/'+ $('#serial_number').val()+'/'+ export_excel;
		}
	});
	
	$("#start_month, #start_day, #start_year, #end_month, #end_day, #end_year").click(function()
	{
		$("#complex_radio").attr('checked', 'checked');
	});
	
	$("#report_date_range_simple").click(function()
	{
		$("#simple_radio").attr('checked', 'checked');
	});
        
        $('#cat').change(function(){
            var _cat = $(this).val();
           
            if(_cat == 0){
                $('#category').show();
                $('#category').val('');
            }else{
                $('#category').hide();
                $('#category').val('');
            }
        });
	
});
</script>